package com.alisls.demo.sso.server.controller;

import com.alisls.demo.sso.server.util.TokenUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述
 *
 * @author Ke Wang
 */
@RestController
@RequestMapping("/token")
public class TokenController {

    /**
     * 校验token有效性
     * @param token 令牌
     * @return 是否有效
     */
    @PostMapping("/check")
    public Boolean check(String token, String clientLogoutUrl, String sessionId) {
        if (!TokenUtil.validToken(token)) {
            return false;
        }

        TokenUtil.SSOClient ssoClient = new TokenUtil.SSOClient(clientLogoutUrl, sessionId);
        TokenUtil.save(token, ssoClient);
        return true;
    }

}
